$(document).ready(function() {		
	$("#query").click(function(){
		var UId=$("#UId").val();
		var duId=$("#duName").val();
		var duId=$("#duPhone").val();
		var psId=$("#psShift").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		$("#personTable").fadeIn("fast");
		$("#loadingPerson").show();
		$.ajax({
  			type: "post",
 			url: "wsq/Person_queryAll.action",
 			data:{
			      "UId":UId,"duId":duId,"psId":psId,
 				  "timeStart":timeStart,
 				  "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#firstPage").click(function(){
		var total=$("#total").text();
		var page=1;
		var maxRow=$("#maxRow").text();
		
		var UId=$("#UId").val();
		var duId=$("#duName").val();
		var duId=$("#duPhone").val();
		var psId=$("#psShift").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
  			type: "post",
 			url: "wsq/Person_queryAll.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"psId":psId,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#prePage").click(function(){		
		var total=$("#total").text();
		var page=$("#page").text();
		var maxRow=$("#maxRow").text();
		
		var UId=$("#UId").val();
		var duId=$("#duName").val();
		var duId=$("#duPhone").val();
		var psId=$("#psShift").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		page=(parseInt(page)-1);
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
			type: "post",
 			url: "wsq/Person_queryAll.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"psId":psId,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#nextPage").click(function(){		
		var total=$("#total").text();
		var page=$("#page").text();
		page=(parseInt(page)+1);
		var maxRow=$("#maxRow").text();
		
		var UId=$("#UId").val();
		var duId=$("#duName").val();
		var duId=$("#duPhone").val();
		var psId=$("#psShift").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
			type: "post",
 			url: "wsq/Person_queryAll.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"psId":psId,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#lastPage").click(function(){
		var total=$("#total").text();
		var page=$("#pageCount").text();
		var maxRow=$("#maxRow").text();
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();
		
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("slow");
		$.ajax({
			type: "post",
 			url: "wsq/Person_queryAll.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"psId":psId,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	$("#jumpPage").click(function(){
		var total=$("#total").text();
		var maxRow=$("#maxRow").text();
		var pageCount=$("#pageCount").text();
		
		var UId=$("#UId").val();
		var duId=$("#duName").val();
		var duId=$("#duPhone").val();
		var psId=$("#psShift").val();
		
		var timeStart=$("#timeStart").val();
		var timeEnd=$("#timeEnd").val();		
		var page=$("#jump").val();
		
		if(page>pageCount){
			alert("jumpPage > pageCount");
			return;
		}
		$("#listPerson").empty();
		$("#loadingPerson").fadeIn("fast");
		$.ajax({
			type: "post",
 			url: "wsq/Person_queryAll.action",
 			data:{"total":total,"page":page,"maxRow":maxRow,
			      "UId":UId,"duId":duId,"psId":psId,
			      "timeStart":timeStart,
			      "timeEnd":timeEnd
 				 },
  			success:showData
		});
	});
	
	function showData(data){
		$("#listPerson").empty();	
		if(data.pageUtil.list.length==0){
			$("#loadingPerson").hide();
			$("#nonePerson").show();
		}else{
			$("#listPerson").hide();
			$("#nonePerson").hide();
		    $("#loadingPerson").hide();
		    $.each(data.pageUtil.list,function(i,n){
				fillDataToHtml(n.tbDuty.duName, n.PDate, n.PDate, n.name,
						  n.tbShift.psShift, n.tbDuty.duPhone);
		  	});
		$("#listPerson").show();
		$("#total").text(data.pageUtil.total);
		$("#page").text(data.pageUtil.page);
		$("#pageCount").text(Math.ceil(data.pageUtil.total/10));
		$("#maxRow").text(data.pageUtil.maxRow);
		}
	}
	
	function fillDataToHtml(duName,PDate,PDate,name,psShift,duPhone){
		var strHtml="<tr>";		
        strHtml+="<td ><div>"+duName+"</div></td>";
        strHtml+="<td ><div>"+PDate.replace(/T/," ")+"</div></td>";
        strHtml+="<td ><div>"+PDate.replace(/T/," ")+"</div></td>";
        strHtml+="<td ><div>"+name+"</div></td>";
        strHtml+="<td ><div>"+psShift+"</div></td>";
        strHtml+="<td ><div>"+duPhone+"</div></td>";
        strHtml+="</tr>";
        $("#listPerson").append(strHtml);
	}
});